<template>
<!-- 常用素材 -->
  <div class="common-material">
    <div class="top">
      <div class="top-item"
        :class="{'active': index === topIndex}" 
        @click="toggleTopItem(index)"
        v-for="(item, index) in topList" :key="index">
        <p class="badge" v-if="item.badge">{{ item.badge }}</p>
        {{ item.name }}
      </div>
    </div>
    <div class="list-wrapper">
      <question-list v-if="topIndex === 0"></question-list>
      <make-video v-if="topIndex === 1"></make-video>
      <make-image v-if="topIndex === 2"></make-image>
      <record-voice v-if="topIndex === 3"></record-voice>
    </div>
  </div>
</template>

<script>
import questionList from '@/components/questionList.vue'
import makeVideo from '@/components/makeVideo.vue'
import makeImage from '@/components/makeImage.vue'
import recordVoice from '@/components/recordVoice.vue'

export default {
  components: {
    questionList,
    makeVideo,
    makeImage,
    recordVoice
  },
  data () {
    return {
      topList: [
        {
          name: '答问题',
          badge: 20
        },
        {
          name: '拍视频',
          badge: 10
        },
        {
          name: '拍图片',
          badge: 10
        },
        {
          name: '录声音',
          badge: 10
        },
      ],
      topIndex: 0
    }
  },
  methods: {
    toggleTopItem (index) {
      this.topIndex = index
    }
  }
}
</script>

<style scoped>
.common-material {
  padding-top: 21.33vw;
  padding-bottom: 21.33vw;
}
.badge {
  position: absolute;
  right: -2vw;
  top: -2vw;
  width: 5.87vw;
  height: 4.27vw;
  line-height: 4.27vw;
  text-align: center;
  font-family: Source Sans Pro;
  font-size: 2.67vw;
  font-weight: 600;
  color: #FFFFFF;
  background: #EE0A24;
  border-radius: 2.13vw;
}
.top-item {
  position: relative;
  width: 21.33vw;
  height: 9.6vw;
  line-height: 9.6vw;
  text-align: center;
  border-radius: 4.8vw;
  background: #F4F4F4;
  font-family: Source Sans Pro;
  font-size: 3.73vw;
  font-weight: 600;
  color: #161616;
  border: 0.27vw solid #E6E6E6;
}
.top-item.active {
  background: #0A67FF;
  color: #fff;
}
.top {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 21.33vw;
  display: flex;
  justify-content: space-evenly;
  align-items: center;
  background: #F8F8FA;
}
</style>